#ifndef HPGDIACT_H
#define HPGDIACT_H
#include <QtGui>
#include "hpgdi.h"
class CHPGDIAct: public CHPGDI
{
        QPainter *m_pdc;
        QBrush   m_brush;
        QPen     m_pen;
        QFont    m_font;
        int paintFlg;
public:
        QPixmap *m_pix;
        CHPGDIAct(QPixmap *pix):CHPGDI()
        {
                paintFlg=0;
                m_pix=pix;
                m_pdc=new QPainter(pix);
                m_font.setPixelSize(12);
        }

        ~CHPGDIAct()
        {
            delete m_pdc;
        }
         void RePix(QPixmap *newpix)
        {
             m_pix=newpix;
        }

virtual void line(int x1,int y1,int x2,int y2,long c)
        {
                int r,g,b;
                r=c&0xff;
                g=(c>>8)&0xff;
                b=(c>>16)&0xff;
                m_pen.setColor(QColor(r,g,b));
                m_pdc->setPen(m_pen);
                m_pdc->drawLine(x1,y1,x2,y2);
         }
virtual void FillRect(int left,int top,int right,int bottom,long c)
        {
                QRect rect(left,top,right-left,bottom-top);
                int r,g,b;
                r=c&0xff;
                g=(c>>8)&0xff;
                b=(c>>16)&0xff;
                m_pdc->setBrush(QColor(r,g,b));
                m_pdc->fillRect( rect,1);
        }

void SetLineType(int t)
{
    m_pen.setStyle((Qt::PenStyle)t);
}
void ResetLineType()
{
    m_pen.setStyle(Qt::SolidLine);
}

virtual void DrawRect(int left,int top,int right,int bottom,long c)
        {
            QRect rect(left,top,right-left,bottom-top);
            int r,g,b;
            r=c&0xff;
            g=(c>>8)&0xff;
            b=(c>>16)&0xff;
            m_pen.setColor(QColor(r,g,b));
            m_pdc->setPen(m_pen);
            m_pdc->drawRect(rect);
        }

virtual void OutText(int x,int y,char *str,long c)
        {
        int r,g,b;
        r=c&0xff;
        g=(c>>8)&0xff;
        b=(c>>16)&0xff;
        m_pdc->setFont(m_font);
        m_pen.setColor(QColor(r,g,b));
        m_pdc->setPen(m_pen);
          y+=GetFontHeight();
        m_pdc->drawText(x,y,str);
        }

virtual int GetStrWidth(char *s)
        {
                QFontMetrics fm(m_font);
                return fm.width(s);
        }
virtual void begin()
{
    if(paintFlg==0)
    {
        m_pdc->begin(m_pix);
    }
    paintFlg++;
}
virtual void end()
{
    paintFlg--;
    if(paintFlg==0)
    {
        m_pdc->end();
    }
}
};
extern CHPGDIAct *MyGDI;
#endif // HPGDIACT_H
